﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BlueCMS.Core.Data.Query.Tables
{
    public class Table : ITable
    {
        public string Name { get; set; }
        public string Alias { get; set; }
        public JoinTable JoinedTo { get; set; }

        public Table(string name)
        {
            Name = name;
        }

        public ITable As(string alias)
        {
            Alias = alias;
            return this;
        }

        public IJoinTable Join(string table)
        {
            return AddJoin(table, JoinType.InnerJoin);
        }

        public IJoinTable CrossJoin(string table)
        {
            return AddJoin(table, JoinType.CrossJoin);
        }

        public IJoinTable LeftJoin(string table)
        {
            return AddJoin(table, JoinType.LeftOuterJoin);
        }

        public IJoinTable RightJoin(string table)
        {
            return AddJoin(table, JoinType.RightOuterJoin);
        }

        public IJoinTable FullJoin(string table)
        {
            return AddJoin(table, JoinType.FullOuterJoin);
        }

        private IJoinTable AddJoin(string name, JoinType type)
        {
            JoinTable joinTable = new JoinTable(name, this, JoinType.InnerJoin);
            JoinedTo = joinTable;
            return joinTable;
        }
    }
}
